
# usage: run this script from terminal
# make sure that u have the hw3.zip submision file in the same folder with this script
# make

import os
import types
import sys
import zipfile

print('######################## structure tests ########################')
zFile = zipfile.ZipFile('hw3.zip')

if (set(zFile.namelist()).intersection(set(os.listdir()))==set()):
	print('--------------Extracting zip file-------------')
	zFile.extractall()
	print('\"hw3\" folder exists - ' + str('hw3' in os.listdir()) )
else: 
	print('can\'t extract zip file - zip file contains files and directories with similar names to those in this folder')
	exit(0)

hw3 = os.listdir('hw3')
print('\n--------------Checking \"hw3\" folder structure--------------')
print('readme file - ' + str('readme.txt' in hw3))
print('scheme-compiler folder - ' + str('scheme-compiler' in hw3))
print('problem-3 folder - ' + str('problem-3' in hw3))

problem_3 = os.listdir('hw3/problem-3')
print('\n--------------Checking \"problem-3\" folder structure--------------')
print('ADTL.cup file - ' + str('ADTL.cup' in problem_3))

scheme_compiler_contents = os.listdir('hw3/scheme-compiler')
print('\n--------------Checking \"scheme-compiler\" folder structure--------------')
print('pc.py file - ' + str('pc.py' in scheme_compiler_contents))
print('tag_parser.py file - ' + str('tag_parser.py' in scheme_compiler_contents))
print('reader.py file - ' + str('reader.py' in scheme_compiler_contents))
print('sexprs.py file - ' + str('sexprs.py' in scheme_compiler_contents))

print('\n--------------Checking static methods existance--------------')
sys.path.insert(0, os.getcwd() + "/hw3/scheme-compiler")


import sexprs
ans = False
try:
	ans = sexprs.AbstractSexpr.readFromString
	ans = True
except:
	pass

print('\"readFromString\" exists in sexprs.AbstractSexpr - '+ str(ans))
print('\"readFromString\" is a static method - ' + str(isinstance(sexprs.AbstractSexpr.readFromString, types.FunctionType))) 


import tag_parser
ans = False
try:
	ans = tag_parser.AbstractSchemeExpr.parse
	ans = True
except:
	pass

print('\n\"parse\" exists in tag_parser.AbstractSchemeExpr - '+ str(ans))
print('\"parse\" is a static method - ' + str(isinstance(tag_parser.AbstractSchemeExpr.parse, types.FunctionType))) 

#------------------------------------------------------------
print('\n--------------Checking new methods existance--------------')

import inspect

ans = False
try:
	ans = tag_parser.AbstractSchemeExpr.debruijn
	ans = True	
except:
	pass

signiture = inspect.getargspec(tag_parser.AbstractSchemeExpr.debruijn)
print('\"debruijn\" exists in tag_parser.AbstractSchemeExpr - '+ str(ans))
print('\"debruijn\" is a method - ' + str('self' in signiture[0] and signiture[0].index('self')==0))
if(signiture[3]):
	print('\"debruijn\" signiture is valid - ' + str((len(signiture[0])-len(list(signiture[3]))==1))) 
else:
	print('\"debruijn\" signiture is valid - ' + str((len(signiture[0])==1))) 

ans = False
try:
	ans = tag_parser.AbstractSchemeExpr.annotateTC
	ans = True
except:
	pass

signiture = inspect.getargspec(tag_parser.AbstractSchemeExpr.annotateTC)
print('\n\"annotateTC\" exists in tag_parser.AbstractSchemeExpr - '+ str(ans))
print('\"annotateTC\" is a method - ' + str('self' in signiture[0] and signiture[0].index('self')==0))
if(signiture[3]):
	print('\"annotateTC\" signiture is valid - ' + str((len(signiture[0])-len(list(signiture[3])))==1)) 
else:
	print('\"annotateTC\" signiture is valid - ' + str((len(signiture[0])==1))) 

print('\n########         Check the above, Good Luck          ########')
